//[]可选参数
String printUserInfo(String userName, [int? age]) {
  if (age != null) {
    return "姓名:$userName --- 年龄:$age";
  }
  return "姓名:$userName --- 年龄保密";
}

//默认参数 尽量把默认参数放在最后 因为还是要按顺序传入参数的
String printInfo(String username, [int? age, String sex = '男']) {
  return "姓名:$username --- 年龄:$age --- 性别:$sex";
}

//命名参数{}
String print1({String? user, int? age}) {
  return "$user---$age";
}

//把方法当做参数的方法

fn1() {
  print("我是fn1");
}

fn2(fn) {
  fn();
}

void main() {
  print(printUserInfo("张三", 18));
  print(printUserInfo("李四"));

  print(printInfo("张三", 20));
  print(printInfo("李四", 30, "女"));

  print(print1(user: "lisi", age: 40));

  fn2(fn1);

  var f = fn1;
  f();
}
